from lxml import etree
import requests
import subprocess
from functools import partial
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
import random
random_float = random.random()
with open("参数加密.js","r",encoding="utf-8")as f:
    data = f.read()
js = execjs.compile(data)

headers = {
    "authority": "www.bczp.cn",
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "max-age=0",
    "referer": "https://www.bczp.cn/search/resume_search_result.aspx?keyword=%BC%F2%C3%C0&ExcludeWorkCity=102200",
    "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "same-origin",
    "sec-fetch-user": "?1",
    "upgrade-insecure-requests": "1",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
cookies = {
    "ASP.NET_SessionId": "5zi3sezc1xhijfwi3l143hqz",
    "EntSearchCookies": "%bc%f2%c3%c0",
    "Hm_lvt_b950e7bc734080ed3826e55d59b0121c": "1704635464",
    "Hm_lpvt_b950e7bc734080ed3826e55d59b0121c": "1704635472"
}
resp = requests.get("https://www.bczp.cn/login/jwlogin.aspx", headers=headers).text
tree = etree.HTML(resp)
pub_key = tree.xpath('//script[contains(text(), "var publicKey")]/text()')
rsa_key = pub_key[0].strip().split("=")[1]
result = js.call("result",rsa_key)
url = "https://www.bczp.cn/ajax/login/jwlogin.ashx"
params = {
    "r": str(random_float)
}
data = {
    "account": result["rsaAccount"],
    "password": result["rsaPassword"],
    "autoLogin": "1",
    "isNormal": "1",
    "key": "4acd32fc-df34-420f-99dc-8d6244166b15"
}
response = requests.post(url, headers=headers, cookies=cookies, params=params, data=data)

print(response.text)
print(response)